#include "reflection_effect_ctrl.h"

#include "effects/reflection_effect.h"
#include "graphics/opengl.h"

namespace venus {
const Effect *ReflectionEffectCtrlGlut::effect() const { return effect_; }

ReflectionEffectCtrlGlut::~ReflectionEffectCtrlGlut() { delete effect_; }

bool ReflectionEffectCtrlGlut::OnSpecialKey(int key, int x, int y) {
  if (NULL == effect_) return false;
  switch (key) {
    case GLUT_KEY_DOWN:
      this->dec_reflection_factor();
      break;
    case GLUT_KEY_UP:
      this->inc_reflection_factor();
      break;
    default:
      return false;
  }
  return true;
}

bool ReflectionEffectCtrlGlut::inc_reflection_factor() {
  float old_val = effect_->reflection_factor();
  float new_val = reflection_factor_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_reflection_factor(new_val);
  return true;
}

bool ReflectionEffectCtrlGlut::dec_reflection_factor() {
  float old_val = effect_->reflection_factor();
  float new_val = reflection_factor_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_reflection_factor(new_val);
  return true;
}

} // namespace venus
